package com.deer.wms.ware.task.model.SO;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.deer.wms.project.root.annotaiton.MyAnnotation;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import java.util.Optional;

/**
 * @author guo
 */
@Getter
@Setter
@Table(name = "so_master")
public class SoMaster {
    /**
     * 主键
     */
    @Id
    @TableId(type = IdType.AUTO)
    @Column(name = "so_master_id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer soMasterId;

    /**
     * 单号
     */
    @Column(name = "bill_no")
    private String billNo;

   /**
    * 波次编码
    */
   private String waveCode;

    /**
     * 0-初始化 1-部分预分配 2-预分配完成 3-部分分配 4-分配完成 5-部分拣货 6-拣货完成 7-部分发运 8-完全发运 9-取消 10-完成
     * <br>
     * 2-已合并
     */
    private Integer state;

    /**
     * 仓库ID
     */
    @Column(name = "ware_id")
    private Integer wareId;
    /**
     * 计划数量
     */
    @Column(name = "so_qty")
    private Double soQty;

  public Double getSoQty() {
   if (ObjectUtil.isNotEmpty(this.soQty)) {
    return this.soQty;
   } else {
    return 0.00;
   }
  }
    /**
     * 计划数量
     */
    @Column(name = "so_qty")
    private Double qcQty;

    /**
     * 仓库编码
     */
    @Column(name = "ware_code")
    private String wareCode;

    /**
     * 仓库名称
     */
    @Column(name = "ware_name")
    private String wareName;

    /**
     * 交易号--履约号
     */
    @Column(name = "trade_no")
    private String tradeNo;

    /**
     * 店铺
     */
    private String shop;

    /**
     * 优先级数值,越大优先级越高
     */
    private Integer priority;

    /**
     * 货主ID
     */
    @Column(name = "organization_id")
    private Integer organizationId;

    /**
     * 货主编码
     */
    @Column(name = "organization_code")
    private String organizationCode;

    /**
     * 货主名称
     */
    @Column(name = "organization_name")
    private String organizationName;


    /**
     * 客户ID
     */
    @Column(name = "customer_id")
    private Integer customerId;

    /**
     * 客户名称(收件人)
     */
    @Column(name = "customer_name")
    private String customerName;

    /**
     * 创建时间
     */
    @Column(name = "create_time")
    private String createTime;

    /**
     * 创建人ID
     */
    @Column(name = "create_user_id")
    private Integer createUserId;

    /**
     * 创建人
     */
    @Column(name = "create_user_name")
    private String createUserName;

    private String outTime;


    private Integer outUserId;


    private String outUserName;

    //下单时间
    private String orderTime;

    /**
     * 交货时间
     */
    @Column(name = "delivery_time")
    private String deliveryTime;

    /**
     * 预期发货时间FM--开工日期
     */
    @Column(name = "expect_time_fm")
    private String expectTimeFm;

    /**
     * 预期发货时间TO
     */
    @Column(name = "expect_time_to")
    private String expectTimeTo;

    /**
     * 优先级
     */
    @Column(name = "order_no")
    private Integer orderNo;

    /**
     * 审核状态   2-等待审核  1-审核通过 0-审核中 -1 -审核退回
     */
    @Column(name = "case_state")
    private Integer caseState;

    /**
     * 单据来源 1-新建
     */
    @Column(name = "bill_source")
    private Integer billSource;

    /**
     * 0-提交  -2保存为草稿
     */
    @Column(name = "insert_type")
    private Integer insertType;

   /**
    * ERP源单id
    */
   private Integer beforeNum;


    private Integer orderBillId;
    /**
     * 自定义1
     */
    @Column(name = "so_udf_hs1")
    private String soUdfHs1;

    /**
     * 自定义2
     */
    @Column(name = "so_udf_hs2")
    private String soUdfHs2;

    /**
     * 自定义2
     */
    @Column(name = "isClose")
    private Integer isClose;

    /**
     * 自定义2
     */
    @Column(name = "dept_id")
    private Integer deptId;

    /**
     * 自定义2
     */
    @Column(name = "dept_name")
    private String deptName;

    /**
     * 自定义3
     */
    @Column(name = "so_udf_hs3")
    private String soUdfHs3;

    /**
     * 备注
     */
    private String memo;


    private Integer carrierId;

    /**
     * 部门名称
     */
    private String carrierName;
    // 订单类型
    private Integer soType;
    // 单据类型名称
    private String soTypeName;

    private String actualDeliveryTime;


    private Integer receivingAddressId;
    /**
     * 分配单据编号
     * */
    private String allotBillNo;

    private Integer soStructure;
    /**
     * 发货编码
     * */
    private String shipCode;
    /**
     * 发货单据编码
     * */
    private String shipBillCode;
    private String expressBillUrl;  //物流面单PDF地址
    private Double totalPrice;  //订单总价

    private Integer checkUserId;
    private String checkUserName;
    private String checkTime;

    private Double weight;
    private Double Length;
    private Double width;
    private Double height;
    private Integer erpState;

    private String lastMileSortingCode;
    private String lastMileDestination;
    private String lastMileLineCode;

    /**
     * 联系人
     */
    @Column(name = "link_man")
    private String linkMan;

    /**
     * 联系电话
     */
    @Column(name = "link_phone")
    private String linkPhone;


    /**
     * 所在国家
     */
    private String country;

    /**
     * 所在省份
     */
    private String province;

    /**
     * 所在城市
     */
    private String city;

    /**
     * 所在区
     */
    private String area;

    /**
     * 详细地址
     */
    @Column(name = "detail_address")
    private String detailAddress;

    /**
     * 发货人联系人
     */
    @Column(name = "ship_link_man")
    private String shipLinkMan;


    /**
     * 联系电话
     */
    @Column(name = "ship_link_phone")
    private String shipLinkPhone;

    /**
     * 所在国家
     */
    private String shipCountry;

    /**
     * 所在省份
     */
    private String shipProvince;

    /**
     * 所在城市
     */
    private String shipCity;

    /**
     * 所在区
     */
    private String shipArea;

    /**
     * 详细地址
     */
    @Column(name = "ship_detail_address")
    private String shipDetailAddress;
    /**
     * 合并单号
     * */
    private String mergeNo;

    private Integer manufactureType;

    private String isTransmit;//是否传输

    //供应商名称
    private String supplierName;
    //供应商id
    private Integer supplierId;
    //订单号
    @MyAnnotation(columnIndex = 0)

    private String orderBillNo;
    //0.未齐套  1.以齐套
    private Integer isVerify;
 private Integer billType;

 @TableField(exist = false)
 private String typeName;

    private Integer assUserId;
    private String assUserName;


    @TableField(value = "ancestral_wave_code")
    //祖籍波次号明细
    private String ancestralWaveCode;


    //当前波次合单人
    @TableField(value = "now_wave_user_name")
    private String nowWaveUserName;
    //当前波次合单人
    @TableField(value = "ancestral_wave_user_name")
    private String ancestralWaveUserName;

    @TableField(value = "sort")
    @MyAnnotation(columnIndex = 1)
    private Integer sort;


    private Integer categoryId;



    /**
     * 是否需要齐套 0不需要 1.需要
     */
    private Integer dispatch;

    public Integer getDispatch() {
   return      Optional.ofNullable(dispatch).orElse(0);
    }

    public Integer getSort() {
        return ObjectUtil.isEmpty(sort) ? 0 : sort;
    }
}
